const findAncestors = require('./findAncestors')
const treeData = require('./treeData')

const defaultItemPropMap = {
  keyProp: 'value',
  deepdashOptions: {
    childrenPath: ['children']
  }
}

function hasAncestor(
  treeData,
  child,
  ancestor,
  propMap = defaultItemPropMap
) {
  const childAncestors = findAncestors(treeData, child, propMap)
  const searchValue = ancestor[propMap.keyProp]
  return childAncestors.some(item => item[propMap.keyProp] === searchValue)
}

module.exports = hasAncestor

console.log(hasAncestor(treeData, { value: 40 }, { value: 47 }, defaultItemPropMap))
